import os

import tornado.ioloop
import tornado.web
from tornado_request_mapping import Route

from handler.http_handler.product_manage import ProductManageHandler
from handler.http_handler.user_manage import USerManageHandler
from handler.ws_handler.digit_twin_handler import DigitTwinHandler
from handler.ws_handler.produce_manage_handler import PMHandler
from init_func import InitFunc

if __name__ == "__main__":
    # todo 到时候把文件路径写死,或者把静态文件复制一份到dist
    web_folder = os.path.join(os.path.dirname(__file__), "web")

    app = tornado.web.Application(
        [
            (r"/(.*)", tornado.web.StaticFileHandler, {"path": web_folder, "default_filename": "index.html"}),
        ]
    )
    route = Route(app)
    route.register(ProductManageHandler)
    route.register(USerManageHandler)
    route.register(PMHandler)
    route.register(DigitTwinHandler)
    app.listen(33356)

    loop = tornado.ioloop.IOLoop.current()
    loop.spawn_callback(InitFunc().init_func)
    loop.start()
